﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using Filmy.Kontroler;
using Filmy.Kontroler.BazaDanych;

namespace Filmy
{
    public partial class Flogowanie : Form
    {
        public Flogowanie()
        {
            InitializeComponent();
            log = new Logowanie();
            tbHaslo.Text = log.haslo;
            tbLogin.Text = log.login;
        }

        Logowanie log;

        private void btZaloguj_Click(object sender, EventArgs e)
        {
            try
            {
                Uzytkownicy uzytkownicy = new Uzytkownicy();
                bool poprawneDane = uzytkownicy.zaloguj(tbLogin.Text, tbHaslo.Text);
                if (poprawneDane)
                {
                    log.zapiszUzytkownika(tbLogin.Text, tbHaslo.Text);
                    this.Visible = false;
                    FNowyFilm nf = new FNowyFilm();
                    nf.Owner = this;
                    nf.Show();
                }
                else
                {
                    MessageBox.Show("Nieprawidłowe dane", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void btAnuluj_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tbHaslo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                btZaloguj_Click(new object(), new EventArgs());
            }
        }

        private void tbLogin_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                btZaloguj_Click(new object(), new EventArgs());
            }
        }
    }
}
